package com.future.mayi.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.baselib.utils.CommonUtils;
import com.future.mayi.R;
import com.future.mayi.fragment.GoodsAllOrderFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class SearchOrderActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.edt_content)
    EditText edtContent;
    @BindView(R.id.tv_search)
    TextView tvSearch;

    private GoodsAllOrderFragment fragment;

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_search_order);
    }

    @Override
    protected void initView() {
        fragment = (GoodsAllOrderFragment) getSupportFragmentManager().findFragmentById(R.id.order_fragment);
    }

    @Override
    protected void initDates() {
        edtContent.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
                if (keyCode == keyEvent.KEYCODE_ENTER) {
                    CommonUtils.hideKeyboard(edtContent, SearchOrderActivity.this);
                    fragment.setSearchContent(edtContent.getText().toString());
                }
                return false;
            }
        });
    }

    @Override
    protected void initListener() {
        CommonUtils.showKeyboard(edtContent);
    }


    @OnClick({R.id.iv_back, R.id.tv_search})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                CommonUtils.hideKeyboard(edtContent, this);
                onBackPressed();
                break;
            case R.id.tv_search:
                if (TextUtils.isEmpty(edtContent.getText())) {
                    toast("请输入搜索内容");
                    return;
                }
                CommonUtils.hideKeyboard(edtContent, this);
                fragment.setSearchContent(edtContent.getText().toString());
                break;
        }
    }
}
